package com.tanhua.server.controller;

import com.tanhua.domain.vo.ContactVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Classname IMController
 * @Description TODO
 * @Date 2021/3/16 15:55
 * @Created by gan
 */
@RestController
@RequestMapping("/messages")
public class IMController {
    @Autowired
    private IMService imService;

    //添加好友
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String,Long> paramMap){
        imService.addContacts(paramMap.get("userId"));
        return ResponseEntity.ok(null);
    }


    //联系人列表
    @GetMapping("/contacts")
    public ResponseEntity queryContactsList(@RequestParam(defaultValue = "1")Integer page,
                                            @RequestParam(defaultValue = "10")Integer pagesize,
                                            @RequestParam(required = false) String keyword){
        PageResult<ContactVo> pageResult=imService
                .queryContactsList(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);

    }


    //查询点赞数
    @GetMapping("likes")
    public ResponseEntity<PageResult>queryLikeList(@RequestParam(defaultValue = "1")Integer page,
                                                   @RequestParam(defaultValue = "10")Integer pagesize){

        return imService.messageCommentList(1,page, pagesize);
    }

    //查询评论列表
    @GetMapping("comments")
    public ResponseEntity<PageResult>queryCommentList(@RequestParam(defaultValue = "1")Integer page,
                                                      @RequestParam(defaultValue = "10")Integer pagesize){
        return imService.messageCommentList(2,page,pagesize);

    }


    //查询喜欢列表
    @GetMapping("loves")
    public ResponseEntity<PageResult> queryLoveList(@RequestParam(defaultValue = "1") Integer page,
                                                    @RequestParam(defaultValue = "10") Integer pageSize) {
        return imService.messageCommentList(3,  page,  pageSize);
    }
}
